/*
 * Text.cpp
 *
 *  Created on: 13/07/2010
 *      Author: alex
 */

#include "TextObject.h"
#include "utils.h"

/*
 * Construtor vazio, só constrói os objetos internos.
 */
TextObject::TextObject(const std::string& text, int x, int y, int fontSize, int style,
		unsigned char red, unsigned char green, unsigned char blue,
		const std::string& fontFile) :
	text(text),
	style(style),
	font(TTF_OpenFont(fontFile.c_str(), fontSize)),
	color(utils::makeColor(red, green, blue)),
	surface(TTF_RenderText_Solid(font, text.c_str(), color)),
	rect(utils::makeRect(x, y, surface->h, surface->w))
{
}

/*
 * O destrutor precisa fechar a fonte liberar a surface.
 */
TextObject::~TextObject() {
	TTF_CloseFont(font);
	SDL_FreeSurface(surface);
}

/*
 * Cola esse texo na tela com BlitSurface.
 */
void TextObject::render(SDL_Surface* screen) {
	SDL_BlitSurface(surface, NULL, screen, &rect);
}
